local fanfu = fk.CreateSkill {
  name = "lingling__fanfu",
}

Fk:loadTranslationTable{
  ["lingling__fanfu"] = "反复",
  [":lingling__fanfu"] = "当你造成或受到伤害后，你可以摸两张牌，然后你下次造成伤害时弃置这些牌。",

  ["@@lingling__fanfu-inhand"] = "反复",
}

local spec = {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(fanfu.name)
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(2, fanfu.name, nil, "@@lingling__fanfu-inhand")
  end,
}

fanfu:addEffect(fk.Damage, spec)
fanfu:addEffect(fk.Damaged, spec)

fanfu:addEffect(fk.DamageCaused, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and
      table.find(player:getCardIds("h"), function(id)
        return Fk:getCardById(id):getMark("@@lingling__fanfu-inhand") > 0 and not player:prohibitDiscard(id)
      end)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local ids = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id):getMark("@@lingling__fanfu-inhand") > 0 and not player:prohibitDiscard(id)
    end)
    room:throwCard(ids, fanfu.name, player, player)
  end,
})

return fanfu
